package gov.ccswj.modules.job.task;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import gov.ccswj.common.utils.R;
import gov.ccswj.modules.bdbusiness.entity.TPageParamEntity;
import gov.ccswj.modules.bdbusiness.service.TPageParamService;
import gov.ccswj.modules.ccbusiness.entity.CCompanyNameEntity;
import gov.ccswj.modules.ccbusiness.entity.CYearreportEntity;
import gov.ccswj.modules.ccbusiness.entity.CYearreportassetsEntity;
import gov.ccswj.modules.ccbusiness.integratedata.IntegrateDate;
import gov.ccswj.modules.ccbusiness.service.CCompanyNameService;
import gov.ccswj.modules.ccbusiness.service.CYearreportService;
import gov.ccswj.modules.ccbusiness.service.CYearreportassetsService;
import gov.ccswj.modules.job.utils.JsonUtils;




/**
 * 
 * 企业年报
 * @author ZhangYx
 * @email ********@gmail.com
 * @date 2017-10-31 11:46:26
 */
@Component("EntAnnReportInfoTask")
public class EntAnnReportInfoTask {
    
    @Autowired
    private CCompanyNameService cCompanyNameService;
    
    @Autowired
    private CYearreportService cYearreportService;
    @Autowired
	private TPageParamService tPageParamService;

    public R runner(String obj){
	    
		 List<CCompanyNameEntity> allCName=new ArrayList<>();
		
		if(obj.equals("0")){
			TPageParamEntity pp=tPageParamService.quary(1);
			allCName = cCompanyNameService.getList(pp.getPagenum(),pp.getLimitnum());
		}else{
			CCompanyNameEntity cname=new CCompanyNameEntity();
			cname.setName(obj.toString());
			allCName.add(cname);
		}	    
	    for (CCompanyNameEntity cCompanyNameEntity : allCName) {
	        String resultdata = IntegrateDate.getCompanyData("getEntAnnReportInfo", cCompanyNameEntity.getName() ,4);
	        List<Object> list=JsonUtils.getdate(resultdata,CYearreportEntity.class);
	        for(Object c:list){
	            CYearreportEntity cm= new CYearreportEntity();
	            cm=(CYearreportEntity)c;
	            cm.setEntname(cCompanyNameEntity.getName());
	            cYearreportService.deleteByname(cm.getEntname());
	            cYearreportService.save(cm);
	        }
        }
		return R.ok();
	}
	
}
